package com.demo.xj_plane.common.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Controller基类
 */
public class BaseController {

    /**
     * 将分页查询查询转为map
     */
    public static Map<String, Object> pageInfoToMap(PagerInfo pagerInfo) {
        Map<String, Object> params = new HashMap<>();
        // 封装查询条件
        for (Condition con : pagerInfo.getConditions()) {
            String name = con.getName();
            String value = con.getValue();
            if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(value)) {
                String tmp = StringUtils.trim(con.getValue());
                tmp = tmp.replaceAll("%", "\\\\%");
                params.put(name, tmp);
            }
        }
        // 封装分页条件
        PageCount pageCount = new PageCount(pagerInfo.getStart(), pagerInfo.getLimit());
        params.put("start", pageCount.getStart());
        params.put("limit", pageCount.getLimit());
        params.put("pageNum", pagerInfo.getStart());
        return params;
    }

}
